package it.koutifaris.travianmap.ui;

public class PointToSquareHelper {

	private final SquareSizeSource squareSizeSource;

	public PointToSquareHelper(final int squareSize) {
		this.squareSizeSource = new SquareSizeSource() {

			@Override
			public int getSquareSize() {
				return squareSize;
			}

		};
	}

	public PointToSquareHelper(SquareSizeSource squareSize) {
		this.squareSizeSource = squareSize;
	}

	public int getSquare(int point) {
		return (int) Math.floor((float) point / getSquareSize());
	}

	public int getSquareCorner(int square) {
		return square * getSquareSize();
	}

	public int getSquareCornerFromPoint(int point) {
		return getSquareCorner(getSquare(point));
	}

	private int getSquareSize() {
		return squareSizeSource.getSquareSize();
	}

	public interface SquareSizeSource {

		int getSquareSize();
	}
}
